package com.liam.apppush.controller;


import com.liam.apppush.client.getui.GeTuiMessageSingleClient;
import com.liam.apppush.client.getui.GeTuiMessageToAppClient;
import com.liam.apppush.client.getui.GeTui_V2Client;
import com.liam.apppush.client.huawei.HaiweiClient;
import com.liam.apppush.client.xiaomi.XiaoMiClient;
import com.liam.apppush.template.getui.GeTuiTemplate;
import com.liam.apppush.vo.MessageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/yogoapi/appPush")
public class AppPushController {

    @Autowired
    private GeTuiMessageSingleClient appPushClient;
    @Autowired
    private GeTuiMessageToAppClient pushMessageToAppClient;
    @Autowired
    private HaiweiClient haiweiClient;
    @Autowired
    private XiaoMiClient xiaoMiClient;
    @Autowired
    private GeTui_V2Client geTui_v2Client;

    @PostMapping("pushToSingle")
    public String pushToSingle(MessageVo messageVo) {
        appPushClient.pushToSingle(messageVo);
        return "ok";
    }

    @PostMapping("pushMessageToApp")
    public String pushMessageToApp(MessageVo messageVo) {
        return  pushMessageToAppClient.pushMessageToApp(messageVo);
    }

    @PostMapping("stopTask")
    public String stopTask(MessageVo messageVo) {
        pushMessageToAppClient.stopTask(messageVo.getTaskId());
        return  "";
    }

    @GetMapping("/geTui/getAccessToken")
    public String getGeTuiAccessToken(MessageVo messageVo) {
        try {
            geTui_v2Client.getAccessToken();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return  "ok";
    }


    @GetMapping("/geTui/addTag")
    public String geTuiaddTag(MessageVo messageVo) {
        try {
            List<String> cids = new ArrayList<>();
            cids.add("e3c171403938672760dfaa0a5238bfb3");
            geTui_v2Client.addTag("游戏",cids);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return  "ok";
    }


    /**
     * {"access_token":"CgB6e3x9nEx48sjTe4FQ2OX4muNxYaDny+7XdnIeGKAKo3QQ/NaQ/TidJTKSHpapz1u80aqtxC2qgx03d1w3d7tb",
     * "token_type":"Bearer","expires_in":3600}
     * @param messageVo
     * @return
     */
    @GetMapping("/huawei/getAccessToken")
    public String getAccessToken(MessageVo messageVo) {
        try {
            haiweiClient.getAccessToken();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return  "ok";
    }
    @GetMapping("/huawei/push")
    public String push(MessageVo messageVo) {
        try {

            List<String> tokens = new ArrayList<>();
            tokens.add("aaa");
            tokens.add("bbbb");
            haiweiClient.sendPushMessage("标题","内容",tokens);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return  "ok";
    }

    @GetMapping("/xiaomi/push")
    public String xiaomiPush(MessageVo messageVo) {
        try {
            xiaoMiClient.sendMessage(messageVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  "ok";
    }

}
